/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.biblioteca8a.dao;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.itschapala.dsw2.biblioteca8a.enumeracion.EstadoPrestamo;
import mx.itschapala.dsw2.biblioteca8a.modelo.Prestamo;
import mx.itschapala.dsw2.biblioteca8a.modelo.Usuario;

/**
 *
 * @author z
 */
@Stateless
public class PrestamoDao extends AbstractDao<Prestamo> implements PrestamoDaoLocal {
    @PersistenceContext(unitName = "Biblioteca8A-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PrestamoDao() {
        super(Prestamo.class);
    }

    @Override
    public List<Prestamo> findIncompleteByUser(Usuario user) {
       Query q=em.createNamedQuery("Prestamo.findIncompleteByUser");
       q.setParameter("estado", EstadoPrestamo.OPEN);
       q.setParameter("idusuario", user.getId());
        return q.getResultList();
    }
    
    
    
}
